﻿package mortal.game.view.platform
{
    import Message.Game.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class PlatformDownLoadController extends Controller
    {
        private var _module:PlatformDownLoadModule;

        public function PlatformDownLoadController()
        {
            return;
        }// end function

        override protected function initView() : IView
        {
            if (this._module == null)
            {
                this._module = new PlatformDownLoadModule();
                this._module.platformData = PlatformDownLoadUtil.getPanelData();
                this._module.updateShow();
                this._module.addEventListener(WindowEvent.SHOW, this.onShow);
                this._module.addEventListener(WindowEvent.CLOSE, this.onClose);
            }
            return this._module;
        }// end function

        protected function onShow(event:WindowEvent) : void
        {
            return;
        }// end function

        protected function onClose(event:WindowEvent) : void
        {
            return;
        }// end function

        override protected function initServer() : void
        {
            Dispatcher.addEventListener(EventName.PlatformDownLoadShow, this.onPlatformViewShow);
            Dispatcher.addEventListener(EventName.PlatformRequestDownLoadGift, this.onRequestGift);
            Dispatcher.addEventListener(EventName.LoginGameSuccess, this.onLoginSuccess);
            NetDispatcher.addCmdListener(ServerCommand.SystemClientSettingGot, this.checkIsShowIcon);
            return;
        }// end function

        private function onRequestGift(event:DataEvent) : void
        {
            GameProxy.Platform.getPlatformDownloadGift(int(event.data), this.onGetPlatformDownloadGiftSuccess);
            return;
        }// end function

        public function onGetPlatformDownloadGiftSuccess(param1:AMI_IRole_getPlatFormGift) : void
        {
            ClientSetting.local.setIsDone(true, IsDoneType.IsGetPlanDownLoadReward);
            this.checkIsShowIcon();
            return;
        }// end function

        private function onLoginSuccess(param1:Object) : void
        {
            this.checkIsShowIcon();
            return;
        }// end function

        private function checkIsReward() : void
        {
            if (!PlatformDownLoadIcon.isViewShow())
            {
                return;
            }
            if (ParamsConst.instance.client == PlatformDownLoadUtil.clientType1 && !ClientSetting.local.getIsDone(IsDoneType.IsGetPlanDownLoadReward))
            {
                PlatformDownLoadIcon.instance.playEffect();
            }
            else
            {
                PlatformDownLoadIcon.instance.stopEffect();
            }
            return;
        }// end function

        private function onPlatformViewShow(event:Event) : void
        {
            if (!isViewShow)
            {
                view.show();
            }
            else
            {
                view.hide();
            }
            return;
        }// end function

        public function checkIsShowIcon(param1 = null) : void
        {
            if (ParamsConst.instance.platformDownLoadUrl && !ClientSetting.local.getIsDone(IsDoneType.IsGetPlanDownLoadReward))
            {
                PlatformDownLoadIcon.instance.showIconByBtnName(PlatformDownLoadUtil.getIconResName());
            }
            else
            {
                if (PlatformDownLoadIcon.isViewShow())
                {
                    PlatformDownLoadIcon.instance.hide();
                }
                if (isViewShow)
                {
                    view.hide();
                }
            }
            this.checkIsReward();
            return;
        }// end function

    }
}
